package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.CstCounterparty;
import com.ruoyi.system.service.ICstCounterpartyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 合同对方Controller
 * 
 * @author zjw
 * @date 2023-01-04
 */
@RestController
@RequestMapping("/cst/counterparty")
public class CstCounterpartyController extends BaseController
{
    @Autowired
    private ICstCounterpartyService cstCounterpartyService;

    /**
     * 查询合同对方列表
     */
    @PreAuthorize("@ss.hasPermi('cst:counterparty:list')")
    @GetMapping("/list")
    public TableDataInfo list(CstCounterparty cstCounterparty)
    {
        startPage();
        List<CstCounterparty> list = cstCounterpartyService.selectCstCounterpartyList(cstCounterparty);
        return getDataTable(list);
    }

    /**
     * 导出合同对方列表
     */
    @PreAuthorize("@ss.hasPermi('cst:counterparty:export')")
    @Log(title = "合同对方", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CstCounterparty cstCounterparty)
    {
        List<CstCounterparty> list = cstCounterpartyService.selectCstCounterpartyList(cstCounterparty);
        ExcelUtil<CstCounterparty> util = new ExcelUtil<CstCounterparty>(CstCounterparty.class);
        util.exportExcel(response, list, "合同对方数据");
    }

    /**
     * 获取合同对方详细信息
     */
    @PreAuthorize("@ss.hasPermi('cst:counterparty:query')")
    @GetMapping(value = "/{counterpartyId}")
    public AjaxResult getInfo(@PathVariable("counterpartyId") Long counterpartyId)
    {
        return success(cstCounterpartyService.selectCstCounterpartyByCounterpartyId(counterpartyId));
    }

    /**
     * 新增合同对方
     */
    @PreAuthorize("@ss.hasPermi('cst:counterparty:add')")
    @Log(title = "合同对方", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CstCounterparty cstCounterparty)
    {
        return toAjax(cstCounterpartyService.insertCstCounterparty(cstCounterparty));
    }

    /**
     * 修改合同对方
     */
    @PreAuthorize("@ss.hasPermi('cst:counterparty:edit')")
    @Log(title = "合同对方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CstCounterparty cstCounterparty)
    {
        return toAjax(cstCounterpartyService.updateCstCounterparty(cstCounterparty));
    }

    /**
     * 删除合同对方
     */
    @PreAuthorize("@ss.hasPermi('cst:counterparty:remove')")
    @Log(title = "合同对方", businessType = BusinessType.DELETE)
	@DeleteMapping("/{counterpartyIds}")
    public AjaxResult remove(@PathVariable Long[] counterpartyIds)
    {
        return toAjax(cstCounterpartyService.deleteCstCounterpartyByCounterpartyIds(counterpartyIds));
    }
}
